package com.cat.dataStructure;

/**
*   @description https://leetcode.cn/problems/maximum-product-of-first-and-last-elements-of-a-subsequence/description/
*   @author 曲大人的喵
*   @create 2025/8/14 15:06
*   @since JDK17
*/

public class Solution08 {
    public long maximumProduct(int[] nums, int m) {
        int n = nums.length;
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        long ans = Long.MIN_VALUE;
        for (int i = m - 1; i < n; i++) {
            int y = nums[i - m + 1];    // 区间m
            min = Math.min(min, y);
            max = Math.max(max, y);
            long x = nums[i];
            ans = Math.max(ans, Math.max(min * x, max * x));
        }
        return ans;
    }
}
